
/*
 * @Description: 
 * @Author: rendc
 * @Date: 2024-10-15 08:55:28
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-15 09:17:26
 */
// 字节流
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
// 字符流
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Test01
 */
public class Test01 {

  public static void main(String[] args) throws Exception {
    // 创建文件字节缓冲流
    FileInputStream fis = new FileInputStream("/Users/cc/Desktop/Java/day33/test.png");
    FileOutputStream fos = new FileOutputStream("/Users/cc/Desktop/Java/day33/test_copy.png");

    // 使用字节输入缓冲流 - 增强流要依赖普通流
    BufferedInputStream bis = new BufferedInputStream(fis);
    // 使用字节输出缓冲流 - 增强流要依赖普通流
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    // 计时
    long start = System.currentTimeMillis();
    // 读取文件
    byte[] bytes = new byte[1024];
    int length;
    while ((length = bis.read(bytes)) != -1) {
      bos.write(bytes, 0, length);
      // 刷新缓冲流
      bos.flush();
    }
    // 计时结束
    long end = System.currentTimeMillis();
    System.out.println("增强流拷贝时间：" + (end - start) + "ms");
    // 关闭流 - 只关闭增强流即可
    bos.close();
    bis.close();
  }
}